package com.xxy.controller;

import com.xxy.entity.Interaction;
import com.xxy.entity.dto.InteractionQueryDTO;
import com.xxy.entity.vo.ProductVO;
import com.xxy.result.PageResult;
import com.xxy.result.Result;
import com.xxy.service.IInteractionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/interaction")
public class InteractionController {
    @Autowired
    private IInteractionService interactionService;

    @PostMapping("/save")
    public Result<String> save(@RequestBody Interaction interaction) {
         interactionService.save(interaction);
        return Result.success("新增成功");
    }

    @PostMapping("/saveOperation/{productId}")
    public Result<String> saveOperation(@PathVariable Long productId) {
        interactionService.saveOperation(productId);
        return Result.success("操作成功");
    }
    //我想要
    @PostMapping("/wantProduct/{productId}")
    public Result<String> wanted(@PathVariable Long productId) {
         return interactionService.wantProduct(productId);
    }
    @DeleteMapping("/deleteBatch")
    public Result<String> deleteBatch(@RequestBody List<Integer> ids) {
        interactionService.removeBatchByIds(ids);
        return Result.success("删除成功");
    }

    @PutMapping("/update")
    public Result<String> update(@RequestBody Interaction interaction) {
        interactionService.updateById(interaction);
        return Result.success("修改成功");
    }

    @PostMapping("/queryByFilter")
    public Result<List<Interaction>> queryByFilter(@RequestBody InteractionQueryDTO interactionQueryDTO) {
        List<Interaction> list = interactionService.queryByFilter(interactionQueryDTO);
        return Result.success(list);
    }
    @GetMapping("/queryCollection")
    public Result<List<ProductVO>> queryCollection() {
        return interactionService.queryCollection();
    }
    //查询浏览商品
    @GetMapping("/queryView")
    public Result<List<ProductVO>> queryView() {
        List<ProductVO> list = interactionService.queryView();
        return Result.success(list);
    }
    //记录浏览行为
    @PostMapping("/view/{productId}")
    public Result<String> view(@PathVariable Long productId) {
        interactionService.view(productId);
        return Result.success("操作成功");
    }

}
